package com.ant.backstage.controller;

import com.ant.backstage.facade.model.User;
import com.ant.backstage.service.UserService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;

/**
 * @author Administrator
 * @date 2021/12/23 0:17
 **/
@RestController
@RequestMapping("/index")
public class indexController {

    private static Logger logger = LogManager.getLogger(indexController.class);

    @Resource
    UserService userService;

//
    @RequiresRoles(value={"admin","user"})//用来判断角色  同时具有 admin user
//    @RequiresPermissions("add") //用来判断权限字符串
    @RequestMapping(value = "/selectOne",method = RequestMethod.POST)
    public User selectOne(Integer id) {
        User user = userService.selectOneUser(id);

        return user;
    }

    //我们可以使用postman进行调用测试 登录前后hello的区别
    @RequestMapping(value = "/hello",method = RequestMethod.GET)
    public String hello(HttpServletRequest request){
        Cookie[] cookies = request.getCookies();
        System.out.println(cookies[0].getValue());
        return "hello";
    }
}
